package tr.com.netgis.web;

import java.text.MessageFormat;
import java.util.Hashtable;

import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;

import tr.com.netgis.util.Constants;
import tr.com.netgis.util.LocalMessageType;

public class SendMessageRequest extends SetLocationRequest implements KvmSerializable {
	
	private String messageType;
	private String messageBody;
	
	public String getMessageType() {
		return messageType;
	}
	
	public void setMessageType(LocalMessageType messageType) {
		this.messageType = messageType.getType();
	}

	public String getMessageBody() {
		return messageBody;
	}

	public void setMessageBody(String messageBody) {
		this.messageBody = messageBody;
	}
	
	public void getPropertyInfo(int index, @SuppressWarnings("rawtypes") Hashtable arg1, PropertyInfo info) {
		if (index == P_MESSAGE_BODY || index == P_MESSAGE_TYPE) {
			 switch (index)
		        {
		        case P_MESSAGE_BODY:
		            info.type = PropertyInfo.STRING_CLASS;
		            info.name = Constants.P_NAME_MESSAGE_BODY;  
		            info.setValue(this.getMessageBody());
		            break;
		        case P_MESSAGE_TYPE:
		            info.type = PropertyInfo.STRING_CLASS;
		            info.name = Constants.P_NAME_MESSAGE_TYPE;
		            info.setValue(this.getMessageType());
		            break;
		        default:
		        	break;
		        }
		} else {
			super.getPropertyInfo(index, arg1, info);
		}
	}
	
	public void setProperty(int index, Object value) {
		if (index == P_MESSAGE_BODY || index == P_MESSAGE_TYPE) {
			switch (index) {
	        case P_MESSAGE_TYPE:
	        	messageType = value != null ? value.toString() : ""; 
	            break;
	        case P_MESSAGE_BODY:
	        	messageBody = value != null ? value.toString() : "";
	            break;   
	        default:
	        	break;
			}
		} else {
			super.setProperty(index, value);
		}
	}
	
	public Object getProperty(int index) {
		if (index == P_MESSAGE_BODY || index == P_MESSAGE_TYPE) {
			switch (index) {
			case P_MESSAGE_BODY:
	            return this.getMessageBody();  
	        case P_MESSAGE_TYPE:
	            return this.getMessageType();
			}
		} 
		return super.getProperty(index);
		
	}

	
	public String toString(){
		String superMsg = super.toString();
		return superMsg + MessageFormat.format("" +
			"Message Type: {0}\n" +
			"Message Body:{1}\n",
			this.getMessageType(),
			this.getMessageBody()
		);	
	}


}
